{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "class Person:\n",
    "    Name = ''\n",
    "    Age = 0\n",
    "    Sex = ''\n",
    "    \n",
    "    def __init__(self,Name,Age,Sex):\n",
    "        self.Name = Name\n",
    "        self.Age = Age\n",
    "        self.Sex = Sex\n",
    "\n",
    "        \n",
    "class Teacher(Person):\n",
    "    title = ''\n",
    "    education_background = ''\n",
    "    salary = 0\n",
    "    bonus = 0\n",
    "    tax = 0\n",
    "    \n",
    "    def __init__(self,Name,Age,Sex,title,education_background,salary,bonus,tax):\n",
    "        super(Teacher, self).__init__(Name,Age,Sex)\n",
    "        self.title = title\n",
    "        self.education_background = education_background\n",
    "        self.salary = salary\n",
    "        self.bonus = bonus\n",
    "        self.tax = tax\n",
    "    \n",
    "    def gross_income(self):\n",
    "        return self.salary+self.bonus-self.tax\n",
    "    \n",
    "    def __lt__(self,other):\n",
    "       return self.Age<other.Age\n",
    "    \n",
    "\n",
    "t = Teacher(\"aa\",5,\"dd\",\"dd\",\"dd\",3,3,3)\n",
    "t.gross_income()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "汽油剩余：32.0L\n",
      "里程数剩余：400.0公里\n",
      "电量剩余：83.0%\n",
      "里程数剩余：498.0公里\n",
      "能量补充完成，本次已添加可跑100.0公里的能量\n",
      "能量补充完成，本次已添加可跑102.0公里的能量\n",
      "汽油剩余：39.2L\n",
      "里程数剩余：490.0公里\n",
      "电量剩余：98.0%\n",
      "里程数剩余：588.0公里\n"
     ]
    }
   ],
   "source": [
    "class EnergySupplementStation:\n",
    "    @staticmethod\n",
    "    def charge(vehicle):\n",
    "        mile = round((100 - vehicle.energy)/100*vehicle.mileage,2)\n",
    "        vehicle.energy = 100\n",
    "        print(\"能量补充完成，本次已添加可跑{}公里的能量\".format(mile))\n",
    "        \n",
    " \n",
    "class Vehicle:\n",
    "    energy = 0\n",
    "    mileage = 0\n",
    "    \n",
    "    def __init__(self,energy,mileage):\n",
    "        self.energy = energy\n",
    "        self.mileage = mileage\n",
    "    \n",
    "    def run(self,mile):\n",
    "        self.energy *= round((1 - mile/self.mileage),2)\n",
    "    \n",
    "    def surplus(self):\n",
    "        pass\n",
    "     \n",
    "    \n",
    "class GasolineVehicle(Vehicle):\n",
    "    def __init__(self):\n",
    "        super(GasolineVehicle, self).__init__(energy = 100,mileage = 500)\n",
    "        \n",
    "    def surplus(self):\n",
    "        print(\"汽油剩余：{}L\\n里程数剩余：{}公里\".format(self.energy/100*40,self.energy/100*self.mileage))\n",
    "    \n",
    "class ElectricVehicle(Vehicle):\n",
    "    def __init__(self):\n",
    "        super(ElectricVehicle, self).__init__(energy = 100,mileage = 600)    \n",
    "    \n",
    "    def surplus(self):\n",
    "        print(\"电量剩余：{}%\\n里程数剩余：{}公里\".format(self.energy,self.energy/100*self.mileage))\n",
    "        \n",
    "gv = GasolineVehicle()\n",
    "ev = ElectricVehicle()\n",
    "gv.run(100)\n",
    "ev.run(100)\n",
    "gv.surplus()\n",
    "ev.surplus()\n",
    "EnergySupplementStation.charge(gv)\n",
    "EnergySupplementStation.charge(ev)\n",
    "gv.run(10)\n",
    "ev.run(10)\n",
    "gv.surplus()\n",
    "ev.surplus()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "总共有4个学生\n"
     ]
    }
   ],
   "source": [
    "class Student:\n",
    "    count = 0\n",
    "    name = ''\n",
    "    age = ''\n",
    "    \n",
    "    def __init__(self,name,age):\n",
    "        self.add_stu()\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "        \n",
    "    @classmethod\n",
    "    def add_stu(cls):\n",
    "        cls.count +=1\n",
    "        \n",
    "    @classmethod\n",
    "    def totl_stu(cls):\n",
    "        print(\"总共有{}个学生\".format(cls.count))\n",
    "        \n",
    "        \n",
    "stu1 = Student(\"jack\", 33)\n",
    "\n",
    "stu2 = Student(\"amy\", 24)\n",
    "\n",
    "stu3 = Student(\"lucy\", 22)\n",
    "\n",
    "stu4 = Student(\"lulu\", 45)\n",
    "\n",
    "Student.totl_stu()\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "tf20",
   "language": "python",
   "name": "tf20"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
